<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0,  user-scalable=0;" >
<title>一生平安-密码修改</title>
<link rel="stylesheet" type="text/css" href="${ctx}/lib/mobile/jquery_mobile_1.0b1/jquery.mobile-1.0b1.min.css" />
	<link rel="stylesheet" type="text/css" href="${ctx}/lib/mobile/css/jszx-scroll.css" />
	<link rel="stylesheet" type="text/css" href="${ctx}/lib/mobile/css/jszx-bar.css" />
	<link rel="stylesheet" type="text/css" href="${ctx}/lib/mobile/css/dynamicPic.css" />
	<link rel="stylesheet" type="text/css" href="${ctx}/lib/mobile/css/mobile.css" />
	<link type="text/css" href="${ctx}/lib/mobile/jquery_mobile_1.0b1/jquery.mobile.datebox.min.css" rel="stylesheet" />
	<script type="text/javascript" src="${ctx}/lib/mobile/jquery_mobile_1.0b1/jquery-1.6.4.min.js"></script>
	<script>
	$(document).bind("mobileinit", function(){
		$.mobile.loadingMessage=false;
		$.mobile.selectmenu.prototype.options.nativeMenu = false;
		$.mobile.defaultPageTransition="none";
		$.mobile.listview.prototype.options.filterPlaceholder="";
	});
	</script>
	<script type="text/javascript" src="${ctx}/lib/mobile/jquery_mobile_1.0b1/jquery.mobile-1.0b1.min.js" charset="utf-8"></script>
	<script type="text/javascript" src="${ctx}/lib/mobile/js/mobile-common.js" charset="utf-8"></script>
	<script type="text/javascript" src="${ctx}/lib/mobile/js/dynamicPic.js" charset="utf-8"></script>
	<script type="text/javascript" src="${ctx}/lib/mobile/js/mobile.js" charset="utf-8"></script>
	<script type="text/javascript" src="${ctx}/lib/mobile/jquery_mobile_1.0b1/jquery.mobile.datebox.js"></script>
	<script type="text/javascript" src="${ctx}/lib/mobile/jquery_mobile_1.0b1/jquery.mobile.datebox.i8n.CHN-S.utf8.js"></script>
</head>
<body>
	<div data-role="page" id="mobile-pwd-change-page" class="page-div-style" style="background: url(${ctx}/lib/mobile/image/reg-bg.png) no-repeat;
				background-size: cover;">
		<script>
		$('#mobile-pwd-change-page').live('pagebeforeshow',function(){
			//显示头部栏
	 		initHeader($("#mobilePwdHeader"),"back");
			//显示功能列表的头部标题名称
			$("#mobilePwdHeader").find("[name='mobileHeaderTitle']").text("密码修改");
			
			//清空所有输入框
			$("#mobile-pwd-change-page").find("input[type='text']").val("");
			$("#mobile-pwd-change-page").find("input[type='password']").val("");
			
			//初始化修改密码
			$("#mobilePwdEditPwd").find("#userPwd").val("");
			$("#mobilePwdEditPwd").find("#newPwd").val("");
			$("#mobilePwdEditPwd").find("#checkNewPwd").val("");
		});
		
		var PwdChangeObj = new Object();
		
		//提醒效果
		PwdChangeObj.errorMsgShow = function(msg){
			$("#mobilePwd_msg").html(msg);
			jQuery.fx.interval = 5;
			$("#mobilePwd_msg").fadeIn('slow',function(){
				$("#mobilePwd_msg").fadeOut(1000);
			});
		}
		
		//验证密码输入
		function checkChangePwd(){
			//原密码
			var userPwd = $.trim($("#mobile-pwd-change-page").find("#userPwd").val());
			if(userPwd.length > 20 || userPwd.length < 4){
				PwdChangeObj.errorMsgShow("原密码 长度： 4~20位 ！");
				return false;
			}
			
			//新密码密码
			var newPwd = $.trim($("#mobile-pwd-change-page").find("#newPwd").val());
			if(newPwd.length > 20 || newPwd.length < 4){
				PwdChangeObj.errorMsgShow("新密码 长度： 4~20位 ！");
				return false;
			}
			
			//新密码确认
			var checkNewPwd = $.trim($("#mobile-pwd-change-page").find("#checkNewPwd").val());
			if(checkNewPwd.length > 20 || checkNewPwd.length < 4){
				PwdChangeObj.errorMsgShow("新密码确认 长度： 4~20位 ！");
				return false;
			}
			
			if(newPwd != checkNewPwd){
				PwdChangeObj.errorMsgShow("两次输入密码不一致！");
				return false;
			}
			
			return true;
		}
		
		//修改密码
		function doChangePwd(){
			$("#mobile-pwd-change-page").find("input[type='text']").blur();
			$("#mobile-pwd-change-page").find("input[type='password']").blur();
			
			//加载等待
			showLoadPage();
			
			if(!checkChangePwd()){
				//结束等待
				hideLoadPage();
				return false;
			}
			
			//密码
			var userPwd = $.trim($("#mobile-pwd-change-page").find("#userPwd").val());
			//新密码
			var newPwd = $.trim($("#mobile-pwd-change-page").find("#newPwd").val());
			
			$.ajax({
                url:"pwdChange.html",
                async: true,
                type:"POST",
                data:{"oldPassword":userPwd,"newPassword":newPwd},
                dataType:"json",
               	success:function(data){	
		            //结束等待
					hideLoadPage();
		            
		            if(data.success == true){
		            	indexObj.showMsgDialog("0","修改成功",function (){
		            		window.location.href = "${ctx}/mobile/logout.html";
		            	});
		            	// 退出，重新登录
		       		} else {
		       			if(data.code == -99){
			       			indexObj.showMsgDialog("0",data.msg,function (){
		       					window.location.href = "${ctx}/mobile/login.html";
			            	});
		       			} else {
		       				indexObj.showMsgDialog("0",data.msg);
		       			}
		       		}
        		},
        		error:function(){
	        		//操作 连接超时
	        		connectionFail();
	       		}
            });
		}
		</script>
		<div id="indexMsg" style="display: none;">
			<div style="position:absolute;width:100%;height:100%;top:0;z-index:50;opacity: 0.5;background-color: black;">
			</div>
			<div style="position:absolute;width:100%;height:100%;top:0;z-index:100;" id="index_showBox">
				<div class="msgbox">
					<div class="tips">提示</div>
					<div class="btnarea">
					</div>
					<div class="btn">
						<div class="div_login" align="center" id="index_showBtn" onclick="indexObj.hideMsgDialog()">
							<div>确定</div>
						</div>
					</div>
				</div>
			</div>
		</div>
		<div id="mobilePwd" class="body_content">
			<div align="center" data-role="header" data-theme="b"  data-position="" id="mobilePwdHeader">
			</div>
			<div id="mobilePwd_msg" class="div_content_06" style="display: none;"></div>
			<div data-role="content" id="mobilePwdWrapper" style="padding:0;margin: 0px;" class="jszx-wrapper">
				<div id="mobilePwdScroller" class="jszx-scroller">
					<div style="height:50px;"></div>
					<div align="center" class="div_content_08">
						<table class="table_list_01">
							<tr>
								<td>原密码</td>
								<td>
									<div class="div_input ui-body-d" style="border: 0;">
										<input type="password" data-role="none" class="input_text" name="userPwd" 
											id="userPwd" placeholder="4~20位密码"/>
									</div>
								</td>
							</tr>
							<tr>
								<td>新密码</td>
								<td>
									<div class="div_input ui-body-d" style="border: 0;">
										<input type="password" data-role="none" class="input_text" name="newPwd" 
											id="newPwd" placeholder="4~20位密码">
									</div>
								</td>
							</tr>
							<tr>
								<td>密码确认</td>
								<td>
									<div class="div_input ui-body-d" style="border: 0;">
										<input type="password" data-role="none" class="input_text" name="checkNewPwd" 
											id="checkNewPwd" placeholder="4~20位密码" style="width: 60%;">
									</div>
								</td>
							</tr>
						</table>
						<table class="table_list_02">
							<tr>
								<td style="height: 80px;">
									<div class="div_login" align="center" id="mobilePwdBtn_changePwd" onclick="doChangePwd();">
										<div>保存</div>
									</div>
								</td>
							</tr>
						</table>
					</div>
				</div>
			</div>
		</div>
	</div>
</body>
</html>